<?php get_header(); ?>
			
			<div id="content">

				<div id="inner-content" class="wrap clearfix">

				    <div id="main" class="eightcol first clearfix" role="main">

                        <ul>
                            <?php
                            $pages = query_posts("post_type=page&post_status=publish&posts_per_page=9999&orderby=menu_order&order=ASC");

                            foreach($pages as $page) {
                                //echo $page->ID . "<br/> ";
                                if($page->post_parent == 0){
                                    $image = wp_get_attachment_image_src( get_post_thumbnail_id( $page->ID ), 'single-post-thumbnail' );

                                    $output = '<li class="sub" id="' . $page->post_title .'">';
                                    $output .= '<img class="full" src="' . $image[0] . '" alt="' . $page->post_title . '>';
                                    $output .= '<article class="text-box">';
                                    $output .= '<h1>' . $page->post_title . '</h1>';
                                    $output .= $page->post_content;
                                    $output .= '</article>';

                                    if(has_children($page->ID)){
                                        $output .= '<ul>';
                                        $subpages = get_pages("child_of=$page->ID");
                                        foreach($subpages as $subpage){
                                            $output .= '<li class="sub" id="' . $subpage->post_title .'">';
                                            $output .= '<img class="full" src="' . $image[0] . '" alt="' . $page->post_title . '>';
                                            $output .= '<article class="text-box">';
                                            $output .= '<h1>' . $subpage->post_title . '</h1>';
                                            $output .= $subpage->post_content;
                                            $output .= '</article>';
                                        }
                                        $output .= '</ul>';
                                    }
                                    $output .= '</li>';

                                    echo $output;
                                }
                            }

                            function has_children($post_id) {
                                $children = get_pages("child_of=$post_id");
                                if( count( $children ) != 0 ) { return true; } // Has Children
                                else { return false; } // No children
                            }
                            ?>
                        </ul>
			
				    </div> <!-- end #main -->
				    
				</div> <!-- end #inner-content -->

			</div> <!-- end #content -->

<?php get_footer(); ?>
